﻿
Option Explicit On

Namespace Blog

    <CLSCompliant(True)> _
    Public Class Post

        Inherits BlogSpark.Common.ObjectBase

#Region "Members"

        Private _PostId As Integer = 0
        Private _BlogId As Integer
        Private _UserId As Integer
        Private _PostCategoryId As Integer
        Private _Subject As String = String.Empty
        Private _Url As String = String.Empty
        Private _MetaTitle As String = String.Empty
        Private _MetaDescription As String = String.Empty
        Private _MetaKeywords As String = String.Empty
        Private _Body As String = String.Empty
        Private _Created As DateTime
        Private _Modified As DateTime
        Private _IsPublished As Boolean = False

#End Region

#Region "Constructors"

        Public Sub New()
        End Sub

#End Region

#Region "Methods"

        Public Overrides Sub Fill(ByVal dr As DataRow)

            _PostId = dr(enumPostFields.PostId)
            BlogID = dr(enumPostFields.BlogId)
            UserID = dr(enumPostFields.UserId)
            PostCategoryID = dr(enumPostFields.PostCategoryId)
            Subject = dr(enumPostFields.Subject)
            URL = dr(enumPostFields.Url)
            MetaTitle = dr(enumPostFields.MetaTitle)
            MetaDescription = dr(enumPostFields.MetaDescription)
            MetaKeywords = dr(enumPostFields.MetaKeywords)
            Body = dr(enumPostFields.Body)
            Created = dr(enumPostFields.Created)
            Modified = dr(enumPostFields.Modified)
            IsPublished = dr(enumPostFields.IsPublished)

        End Sub

        Public Sub Save()

            If _PostId = 0 Then
                _PostId = BlogSpark.DataProvider.SPs.InsertPost(BlogSpark.DataProvider.Data.ConnectionType, BlogID, UserID, Subject, URL, MetaTitle, MetaDescription, MetaKeywords, Body, Modified, IsPublished)
            Else
                BlogSpark.DataProvider.SPs.UpdatePost(BlogSpark.DataProvider.Data.ConnectionType, PostID, BlogID, UserID, Subject, URL, MetaTitle, MetaDescription, MetaKeywords, Body, Created, Modified, IsPublished)
            End If

        End Sub

        Public Sub Delete()

            BlogSpark.DataProvider.SPs.DeletePost(BlogSpark.DataProvider.Data.ConnectionType, PostID)

        End Sub

#End Region

#Region "Properties"

        Public ReadOnly Property PostID() As Integer
            Get
                Return _PostId
            End Get
        End Property

        Public Property BlogID() As Integer
            Get
                Return _BlogId
            End Get
            Set(ByVal value As Integer)
                _BlogId = value
            End Set
        End Property

        Public Property UserID() As Integer
            Get
                Return _UserId
            End Get
            Set(ByVal value As Integer)
                _UserId = value
            End Set
        End Property

        Public Property PostCategoryID() As Integer
            Get
                Return _postCategoryId
            End Get
            Set(ByVal value As Integer)
                _postcategoryid = value
            End Set
        End Property

        Public Property Subject() As String
            Get
                Return _Subject
            End Get
            Set(ByVal value As String)
                _Subject = value
            End Set
        End Property

        Public Property URL() As String
            Get
                Return _Url
            End Get
            Set(ByVal value As String)
                _Url = value
            End Set
        End Property

        Public Property MetaTitle() As String
            Get
                Return _MetaTitle
            End Get
            Set(ByVal value As String)
                _MetaTitle = value
            End Set
        End Property

        Public Property MetaDescription() As String
            Get
                Return _MetaDescription
            End Get
            Set(ByVal value As String)
                _MetaDescription = value
            End Set
        End Property

        Public Property MetaKeywords() As String
            Get
                Return _MetaKeywords
            End Get
            Set(ByVal value As String)
                _MetaKeywords = value
            End Set
        End Property

        Public Property Body() As String
            Get
                Return _Body
            End Get
            Set(ByVal value As String)
                _Body = value
            End Set
        End Property

        Public Property Created() As DateTime
            Get
                Return _Created
            End Get
            Set(ByVal value As DateTime)
                _Created = value
            End Set
        End Property

        Public Property Modified() As DateTime
            Get
                Return _Modified
            End Get
            Set(ByVal value As DateTime)
                _Modified = value
            End Set
        End Property

        Public Property IsPublished() As Boolean
            Get
                Return _IsPublished
            End Get
            Set(ByVal value As Boolean)
                _IsPublished = value
            End Set
        End Property

#End Region

#Region "Enums"

        Private Enum enumPostFields As Byte

            PostId = 0
            BlogId
            UserId
            PostCategoryId
            Subject
            Url
            MetaTitle
            MetaDescription
            MetaKeywords
            Body
            Created
            Modified
            IsPublished

        End Enum

#End Region

    End Class

End Namespace

